//------------------------------------------------------------------------------
//
//   Go4Flex 
//   Copyright 2010 
//   All rights reserved. 
//
//------------------------------------------------------------------------------

package com.go4flex.usermanager.usercontrol.view.renderer
{
	import com.go4flex.usermanager.usercontrol.vo.GroupVO;
	import com.go4flex.usermanager.usercontrol.vo.PermissionVO;

	import mx.containers.Canvas;
	import mx.controls.Label;
	import mx.controls.listClasses.BaseListData;
	import mx.controls.listClasses.IDropInListItemRenderer;

	public class PermissionsRenderer extends Canvas implements IDropInListItemRenderer
	{

		private var _listData:BaseListData;

		public function PermissionsRenderer()
		{
			super();
		}

		private var permissionsLbl:Label;

		override public function set data(value:Object):void
		{
			super.data = value;

			if (value != null && permissionsLbl != null)
			{
				var item:GroupVO = value as GroupVO;
				var perms:Array = [];
				for (var i:uint = 0; i < item.permissions.length; i++)
				{
					perms.push((item.permissions[i] as PermissionVO).name);
				}
				permissionsLbl.text = perms.join(",");

			}
		}

		[Bindable("dataChange")]
		public function get listData():BaseListData
		{
			return _listData;
		}

		public function set listData(value:BaseListData):void
		{
			_listData = value;
		}

		override protected function createChildren():void
		{
			// create first name label
			permissionsLbl = new Label();
			permissionsLbl.setStyle("verticalCenter", 0);
			permissionsLbl.setStyle("left", 5);
			addChild(permissionsLbl);


			super.createChildren();
		}


	}
}